using ASP;
using HoWave.Web.Shop.Member;
using System;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_PassportIndex : Member, IRequiresSessionState
{
	protected Literal TxtQuestion;
	protected HyperLink hlQuestionLink;
	protected Literal TxtAnswer;
	protected Literal TxtEmail;
	protected Literal TxtPassword;
	protected Button Button1;
	protected Panel pnlCheck;
	protected DropDownList H_UserQuestion;
	protected TextBox H_UserAnswer;
	protected Button btnAddQuestion;
	protected Panel pnlAddQuestion;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (base.ActionTabInfo == "addinfo")
			{
				this.pnlAddQuestion.Style["display"] = "";
				this.pnlCheck.Style["display"] = "none";
				this.H_UserQuestion.DataSource = this.GetQuestionList();
				this.H_UserQuestion.DataBind();
			}
			else
			{
				this.pnlAddQuestion.Style["display"] = "none";
				this.pnlCheck.Style["display"] = "";
				string text = base.user.UserRes["Question"].ToString();
				if (!string.IsNullOrEmpty(text))
				{
					this.hlQuestionLink.Text = "修改";
					this.hlQuestionLink.NavigateUrl = "../Passport/PasswordManager.aspx?action=edit";
					this.hlQuestionLink.Target = "_blank";
				}
				else
				{
					this.hlQuestionLink.Text = "设置问题";
					text = "未设置";
					this.hlQuestionLink.NavigateUrl = "PassportIndex.aspx?Action=addinfo";
				}
				this.TxtQuestion.Text = text;
				this.TxtAnswer.Text = ((base.user.UserRes["Question"].ToString() == "") ? "" : "******");
				this.TxtEmail.Text = base.user.UserEmail;
			}
		}
	}
	protected void btnAddQuestion_Click(object sender, EventArgs e)
	{
		string selectValue = this.H_UserQuestion.GetSelectValue(new string[0]);
		string text = this.H_UserAnswer.Text;
		if (!string.IsNullOrEmpty(text))
		{
			text = this.Md5(text, 32);
			if (base.user.UserID > 0)
			{
				string sql = string.Concat(new object[]
				{
					"update HL_User set Question='",
					selectValue,
					"',Answer='",
					text,
					"' where UserID=",
					base.user.UserID
				});
				int num = this.conn.Execute(sql);
				if (num > 0)
				{
					this.WriteSuccessMsg("", "问题设置成功！", "PassportIndex.aspx");
				}
				else
				{
					this.WriteErrMsg("", "问题设置失败！", "");
				}
			}
		}
		else
		{
			this.WriteErrMsg("", "答案不能为空!", "");
		}
	}
}
